package com.xiaotu.service.user.impl;

import com.xiaotu.dao.user.WxUserMapper;
import com.xiaotu.dto.WxUserDto;
import com.xiaotu.service.user.WxUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @author zhangxiao
 * @create 2021-08-17 16:03
 */
@Service
@AllArgsConstructor
public class WxUserServiceImpl implements WxUserService<WxUserDto> {

    private final WxUserMapper wxUserMapper;

    @Override
    public Integer insertWxUser(WxUserDto wxUserDto) {
        return wxUserMapper.insert(wxUserDto);
    }

    @Override
    public void updateWxUser(WxUserDto wxUserDto) {
        wxUserMapper.updateByPrimaryKey(wxUserDto);
    }

    @Override
    public WxUserDto queryWxUserByUserId(Integer userId) {
        return wxUserMapper.selectByPrimaryKey(userId);
    }

    @Override
    public WxUserDto queryWxUserByOpenId(String openId) {
        Example example = new Example(WxUserDto.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("openId", openId);
        return wxUserMapper.selectOneByExample(example);
    }
}
